﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class 练习_parameters : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            OleDbConnection connection = new OleDbConnection(conn.Connstr);
            OleDbCommand selectcommond = connection.CreateCommand();
            OleDbCommand nonquerycommand = connection.CreateCommand();
            selectcommond.CommandTimeout = 15;
            nonquerycommand.CommandTimeout = 15;
            selectcommond.CommandText = "select count(*) from admin;";
            nonquerycommand.CommandText = "insert into [admin]([id],[username],[password]) " + "VALUES(@paraid,@parausername,@parapassword)";
            nonquerycommand.Parameters.Add("@paraid", OleDbType.WChar, 10);
            nonquerycommand.Parameters.Add("@parausername", OleDbType.WChar, 50);
            nonquerycommand.Parameters.Add("@parapassword", OleDbType.WChar, 50);
            connection.Open();
            Response.Write("插入前表中的记录总数" + selectcommond.ExecuteScalar());
            nonquerycommand.Prepare();
            nonquerycommand.Parameters["@paraid"].Value = 3;
            nonquerycommand.Parameters["@parausername"].Value = "danye";
            nonquerycommand.Parameters["@parapassword"].Value = "1234560";
            Response.Write("将要执行的sql语句是:{0}" + nonquerycommand.CommandText);
            Response.Write("执行录入操作影响的行数是" + nonquerycommand.ExecuteNonQuery().ToString());
            Response.Write("插入成功");
        }
        catch (OleDbException ex)
        {
            Response.Write(ex);
        
        }


    }
}
